<?php

import("data.db.DbTable");
import("data.db.DbFactory");

class DbRemoteStorage extends DbTable {
	
	const TB_TABLENAME	= "rstorage";
	const TB_I			= 'rstrg';

	const TB_NAME		= 'rstrg_name';
	const TB_CLASS		= 'rstrg_class';
	const TB_CAPACITY	= 'rstrg_capacity';
	const TB_SPEED		= 'rstrg_speed';
	const TB_RATING		= 'rstrg_rating';
	
	public static function _get_TABLENAME() {return self::TB_TABLENAME;}
	public static function _get_ID() {return self::TB_I."_id";}
	public static function _get_SUFFIX() {return self::TB_I;}
	
	public $name;
	public $class;
	public $capacity;
	public $speed;
	public $rating;
	
	function DbRemoteStorage() {
		parent::DbTable();
	}
	
	function setName($name) {$this->name = $name;}
	function getName() {return $this->name;}
	
	function setClass($class) {$this->class = $class;}
	function getClass() {return $this->class;}
	
	function setCapacity($capacity) {$this->capacity = $capacity;}
	function getCapacity() {return $this->capacity;}
	
	function setSpeed($speed) {$this->speed = $speed;}
	function getSpeed() {return $this->speed;}
	
	function setRating($rating) {$this->rating = $rating;}
	function getRating() {return $this->rating;}
	
	function setFile(&$file) {
		$this->setForwardForeign(TB_FILE_TABLENAME, $file);
	}
	function getFile() {
		$f = $this->getForwardForeign(TB_FILE_TABLENAME);
		return $f->getForeign();
	}
	
	function fillEntity($arrResult) {
		parent::fillEntity($arrResult);
		$this->setName($arrResult[self::TB_NAME]);
		$this->setClass($arrResult[self::TB_CLASS]);
		$this->setCapacity($arrResult[self::TB_CAPACITY]);
		$this->setSpeed($arrResult[self::TB_SPEED]);
		$this->setRating($arrResult[self::TB_RATING]);
	}
	
	//store
	function fillFields() {
		parent::fillFields();
		$this->fildsForStore[self::TB_NAME] = "'".$this->getName()."'";
		$this->fildsForStore[self::TB_CLASS] = "'".$this->getClass()."'";
		$this->fildsForStore[self::TB_CAPACITY] = $this->getCapacity();
		$this->fildsForStore[self::TB_SPEED] = $this->getSpeed();
		$this->fildsForStore[self::TB_RATING] = $this->getRating();
	}
	
	function findAll() {
		return parent::__selectAllByCriteria(null, 'data.logic.catalog.LRemoteStorage');
	}
	
	function findByName($name) {
		return parent::__selectByCriteria(
			self::TB_NAME."='".$name."'",
			'data.logic.catalog.LRemoteStorage');
	}
	
	/*function findByNameAndFile($name, $file) {
		return parent::__selectByCriteria(
			self::TB_NAME."='".$name."' and ".
			$this->_get_F('data.logic.catalog.LRemoteStorage', DbFactory::getClass(TB_FILE_TABLENAME) )."=".$file->getId(),
			DbFactory::getClass(TB_RSTORAGE_TABLENAME));
	}*/
}
?>